#include "LookAtMatrix.hpp"

LookAtMatrix::LookAtMatrix( MVector3D& eyev, MVector3D& centerv, MVector3D& upv )
{
	m_eye = eyev;
	m_center = centerv;
	m_up = upv;

	MVector3D look = m_center - m_eye;
	look.Normalize();

	MVector3D side = look.CrossProduct( m_up );
	side.Normalize();

	MVector3D up = side.CrossProduct( look );

	MMatrix4 tempMatrix = MMatrix4( side.x, up.x, -look.x, 0,
		                            side.y, up.y, -look.y, 0,
			                        side.z, up.z, -look.z, 0,
						            0,   0,    0, 1 );

	MMatrix4 translationMat = MMatrix4( 1,   0,      0,      0,
		                                0,   1,      0,      0,
										0,   0,      1,      0,
										-m_eye.x, -m_eye.y, -m_eye.z, 1 );

	m_modelViewMatrix = translationMat * tempMatrix;
}

LookAtMatrix::~LookAtMatrix()
{
}

const MMatrix4& LookAtMatrix::GetModelViewMatrix() const
{
	return m_modelViewMatrix;
}